<template>
  <div class='app-container'>
    <div class="info_box_top">
        <p class="backgo" @click="go_backs"><i class="iconfont icon-left"></i>返回</p>
        <i class="iconfont icon-baoxianchanpin"></i><span>出单工号编辑</span>
    </div>
    <div class='staff'>
      <el-form :model="formLabel" label-width="150px" :inline="true" :rules="rules" ref="formLabel">
        <div class="firstM clearfix">
          <div class="form-top1">
            <!-- <i class="el-icon-menu"></i> -->
            <span class="form-title">
                        工号信息
                    </span>
          </div>
          <div class='form-staff cleafix'>
            <div class='form-tab'>
              <el-row>
                <el-col :span='12'>
                  <el-form-item label="保险公司：" class="is-required" prop="insuranceId">
                    <el-select class="wd230" size="mini" v-model="formLabel.insuranceId" placeholder="请选择保险公司" @change='toSystem'>
                      <el-option-group v-for="group in companies" :key="group.letter" :label="group.letter">
                        <el-option v-for="item in group.insurances" :key="item.id" :label="item.insuranceName" :value="item.id">
                        </el-option>
                      </el-option-group>
                    </el-select>
                  </el-form-item>
                  <el-form-item label='登录账号：' prop='staffAccount'>
                    <el-input size="mini" class="wd230" v-model='formLabel.staffAccount'></el-input>
                  </el-form-item>
                  <el-form-item label="机构代码：">
                    <el-input v-model="formLabel.insuranceCode" size="mini" class="wd230"></el-input>
                  </el-form-item>
                  <el-form-item label="工号描述：" class="is-required" prop="describe">
                    <el-input v-model="formLabel.describe" placeholder="请填写工号描述" size="mini" class="wd230"></el-input>
                  </el-form-item>
                  <el-form-item label="子账号：" v-if="subaccount">
                    <el-input v-model="formLabel.childAccount"  placeholder="请填写子账号" size="mini" class="wd230"></el-input>
                  </el-form-item>
                  
                   <el-form-item label="子账号密码：" v-if="subaccount">
                    <el-input v-model="formLabel.childPassword"  placeholder="请填写子账号密码" size="mini" class="wd230"></el-input>
                  </el-form-item>
                  <el-form-item label="决策单元代码：" v-if="ishaveBatchNumber">
                    <el-input v-model="formLabel.batchNumber" placeholder="请填写决策单元代码" size="mini" class="wd230"></el-input>
                  </el-form-item>
                  <el-form-item label="保险公司业务员：" v-if="ishaveInsuranceSalesman">
                    <el-input v-model="formLabel.insuranceSalesman" placeholder="请填写保险公司业务员" size="mini" class="wd230"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span='12'>
                  <el-form-item label="业务系统：" prop='insuranceSystemId'>
                    <el-select v-model="formLabel.insuranceSystemId" placeholder="请选择" size="mini" class="wd230">
                      <el-option v-for="item in types" :value-key="item.id" :value="item.id" :label="item.systemName">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="登录密码：" prop='staffPassword'>
                    <el-input v-model="formLabel.staffPassword" placeholder="" size="small" class="wd230"></el-input>
                  </el-form-item>
                  <el-form-item label="手机号：">
                    <el-input v-model="formLabel.phoneNumber" placeholder="" size="mini" class="wd230"></el-input>
                  </el-form-item>
                  <el-form-item label="状态：">
                    <el-select v-model="formLabel.isActive" placeholder="请选择" size="mini" class="wd230">
                      <el-option v-for="item in status2" :key="item.value2" :value="item.isActive" :label="item.value2">
                      </el-option>
                    </el-select>
                  </el-form-item>
                   
                  
                  <el-form-item label="业务员身份证号：" v-if="ishaveSalesmanIdentityCard">
                    <el-input v-model="formLabel.salesmanIdentityCard" placeholder="请填写保险公司业务员身份证号" size="mini" class="wd230"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </div>
        </div>
        <div class="firstM clearfix">
        <div class="form-top1">
          <!-- <i class="el-icon-menu"></i> -->
          <span class="form-title">
                          出单网络信息
                      </span>
        </div>
        <div class='form-staff'>
          <div class='form-tab'>
            <el-row>
              <el-col :span='12'>
                <el-form-item label="VPN地址：">
                  <el-input v-model="formLabel.vpnAddress" placeholder="" size="mini" class="wd230"></el-input>
                </el-form-item>
                <el-form-item label="VPN登录密码：">
                  <el-input v-model="formLabel.vpnPassword" placeholder="" size="small" class="wd230"></el-input>
                </el-form-item>
                <el-form-item label="IP地址：">
                  <el-input v-model="formLabel.ip" placeholder="" size="mini" class="wd230"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span='12'>
                <el-form-item label="VPN登录名：">
                  <el-input v-model="formLabel.vpnAccount" placeholder="" size="mini" class="wd230"></el-input>
                </el-form-item>
                <el-form-item label="Mac地址：">
                  <el-input v-model="formLabel.mac" placeholder="" size="mini" class="wd230"></el-input>
                </el-form-item>
                <el-form-item label="机器码：">
                  <el-input v-model="formLabel.machineCode" placeholder="" size="mini" class="wd230"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </div>
        </div>
        <div v-if='organization' class="firstM clearfix">
          <div class="form-top1">
            <!-- <i class="el-icon-menu"></i> -->
            <span class="form-title">
                              服务机构信息
                        </span>
          </div>
          <div class='form-staff'>
            <div class='form-tab'>
              <el-row>
                <el-col :span='12'>
                  <el-form-item label="归属机构名称：">
                    <el-input placeholder="" size="mini" class="wd230" v-model='formLabel.belongOrganizationName'></el-input>
                  </el-form-item>
                  <el-form-item label="归属业务员名称：">
                    <el-input placeholder="" size="mini" class="wd230" v-model='formLabel.belongUserName'></el-input>
                  </el-form-item>
                  <el-form-item label="代理/经纪人名称：">
                    <el-input placeholder="" size="mini" class="wd230" v-model='formLabel.agentName '></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span='12'>
                  <el-form-item label="归属机构代码：">
                    <el-input placeholder="" size="mini" class="wd230" v-model='formLabel.belongOrganizationCode '></el-input>
                  </el-form-item>
                  <el-form-item label="归属业务员代码： ">
                    <el-input placeholder="" size="mini" class="wd230" v-model='formLabel.belongUserCode '></el-input>
                  </el-form-item>
                  <el-form-item label="代理/经纪人代码： ">
                    <el-input placeholder="" size="mini" class="wd230" v-model='formLabel.agentCode'></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span='24'>
                  <el-form-item label="代理/经纪协议代码： ">
                    <el-input placeholder="" size="mini" class="wd230" v-model='formLabel.agentAgreementCode '></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span='12'>
                  <el-form-item label="服务机构业务员名称：  ">
                    <el-input placeholder="" size="mini" class="wd230" v-model='formLabel.serviceOrganizationUserName'></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span='12'>
                  <el-form-item label="服务机构业务员代码： ">
                    <el-input placeholder="" size="mini" class="wd230" v-model='formLabel.serviceOrganizationUserCode'></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- <el-row>
                <el-col :span='24'>
                  <el-form-item label="指定查询地区：" class="offsetR floatLeft regionId">
                    <el-select size="mini" v-model='inquire1' @change='inquireChange2'>
                      <el-option v-for='item in inquires' :key="item.key" :label="item.value" :value="item.key">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item class="offsetR  floatLeft">
                    <el-select size="mini" v-model='formLabel.inquire2' @change='inquireChange3'>
                      <el-option v-for='item in inquires2' :key="item.key" :label="item.value" :value="item.key">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item class="offsetR  floatLeft">
                    <el-select size="mini" v-model='formLabel.inquire3' @change='inquireChange4'>
                      <el-option v-for='item in inquires3' :key="item.key" :label="item.value" :value="item.key">
                      </el-option>
                    </el-select>
                    <div class="hiddenInput">
                      <el-input type="hidden" v-model="formLabel.searthArea" style='dsiplay:none'></el-input>
                    </div>
                  </el-form-item>
                </el-col>
              </el-row> -->
            </div>
          </div>
        </div>
        <!-- <div class='form-staff'>
                    <div class='form-tab'>
                        <el-row>
                            <el-col :span='12'>
                                
                            </el-col>
                            <el-col :span='12'></el-col>
                        </el-row>
                    </div>
                </div> -->
        <div class="firstM clearfix">       
          <div class="form-top1">
            <!-- <i class="el-icon-menu"></i> -->
            <span class="form-title">
                            其它信息
                        </span>
          </div>
          <div class='form-staff'>
            <div class='form-tab'>
             <!--  <el-row>
                <el-col :span='12'>
                  <el-form-item label="出单平台锁定登录：">
                    <el-select v-model="formLabel.isSystemLocked" placeholder="请选择" size="mini" class="wd230">
                      <el-option v-for="item in status" :key="item.value" :value="item.isSystemLocked" :label="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span='12'>
                  <el-form-item label="使用录单：">
                    <el-select v-model="formLabel.isRecord" placeholder="请选择" size="mini" class="wd230">
                      <el-option v-for="item in status3" :value-key="item.value3" :value="item.isRecord" :label="item.value3">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>-->
              <el-row> 
                <el-col :span='24'>
                  <el-form-item label="工号所属区域：" class="offsetR is-required floatLeft regionId" prop="regionId">
                    <el-select v-model="value1" placeholder="请选择省" @change='linkage2' size="mini">
                      <el-option v-for="item in aoptions" :key="item.key" :label="item.value" :value="item.key">
                      </el-option>
                    </el-select>
                    <div class="hiddenInput">
                      <el-input type="hidden" v-model="formLabel.regionId" style='display:none'></el-input>
                    </div>
                  </el-form-item>
                  <el-form-item class="offsetR is-required floatLeft" prop="value2">
                    <el-select v-if="id!=0" v-model="formLabel.value2" placeholder="请选择市" @change='linkage3' size="mini">
                      <el-option v-for="item in boptions" :key="item.key" :label="item.conentname" :value="item.key">
                        <span>{{ item.value }}({{ item.plateCode}})</span>
                      </el-option>
                    </el-select>
                    <el-select v-else v-model="formLabel.value2" placeholder="请选择市" @change='linkage3' size="mini">
                      <el-option v-for="item in boptions" :key="item.key" :label="item.conentname" :value="item">
                        <span>{{ item.value }}({{ item.plateCode}})</span>
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item class="offsetR is-required floatLeft">
                    <el-select v-model="value3" placeholder="请选择区" @change='linkage4' size="mini">
                      <el-option v-for="item in coptions" :key="item.key" :label="item.value" :value="item.key">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span='24'>
                  <el-form-item label="关联组织：" class="offsetR toBlock" prop='tree'>
                  <ztree-select class="wd500" v-model="formLabel.tree"  multiple :treedata="treedata" :childprops="childprops"></ztree-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span='24'>
                  <el-form-item label="备注信息：" class="offsetR toBlock">
                    <el-input type="textarea" :autosize="{minRows:3}" placeholder="请输入内容" v-model="formLabel.remark" style="width:567px">
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </div>
        </div>
        <div class="toCenter">
          <el-button type="info" size="small" @click="go_backs">取消</el-button>
          <el-button type="primary" size="small" @click="submitForm('formLabel')" :loading="loading">保存</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
	import Vue from 'vue'
import ztreeSelect from "@/components/z-select/index.vue";
export default {
 
  data() {
    return {
    	subaccount:false,
      loading:false,
      taishan: false,
      value1: '',
       childprops: {
        name: "displayName", //显示名字
        children: "orgs", //子级字段名
        lv: "depth" //当前层级
      },
      organizationUnitTree: [],
      openTree: false,
      //公司数据
      companies: [],
      treedata:[],
      aoptions: [],
      insuranceName: '',
      tree:[],
      inquires2: [],
      inquires3: [],
      inquires: [],
      coptions: [],
      value3: '',
      options: [],
      value2: '',
      boptions: [],
      inquire1: '',
      inquire2: '',
      inquire3: '',
      organization: false,
      type: '',
      types: [],
      // types:[{
      //     type: "业务归属",
      //     id: "0"
      // }],
      status: [{
        isSystemLocked: true,
        value: '正常'
      }, {
        isSystemLocked: false,
        value: '禁用'
      }],
      status2: [{
        isActive: true,
        value2: '正常'
      }, {
        isActive: false,
        value2: '禁用'
      }],
      status3: [{
        isRecord: true,
        value3: '正常'
      }, {
        isRecord: false,
        value3: '禁用'
      }],

      // 省数据
      provices: [],
      // 市数据
      cities: [],
      // 区数据
      areas: [],
      org: '选择组织',
      orgs: [],
      regionIds: [],
      formLabel: {
        // type:'0',
        insuranceId: '',
        isSystemLocked: true,
        isActive: true,
        isRecord: true,
        value2: '',
        type: '',
        tree:[],
      },
      defaultProps: {
        children: 'organizationUnits',
        label: 'displayName'
      },
      //级联
      options2: [],
      props: {
        value: 'key',
        label: 'value',
        children: 'children'
      },
      rules: {
        insuranceId: [{ required: true, message: '请输入保险公司', trigger: 'change' }],
        staffPassword: [{ required: true, message: '请输入密码', trigger: 'blur' }],
        staffAccount: [{ required: true, message: '请输入工号', trigger: 'blur' }],
        describe: [{ required: true, message: '请输入工号描述', trigger: 'blur' }],
        regionId: [{ required: true, message: '请选择完整的区域', trigger: 'change' }],
        value2: [{ required: true, message: '请选择完整的区域', trigger: 'change' }],
        tree: [{ required: true, message: '请至少选择一个组织', trigger: 'change' }],
        insuranceSystemId: [{ required: true, message: '请输入业务系统', trigger: 'change' }],
        staffPassword:[{ required: true, message: '请输入密码', trigger: 'change' }],
        staffAccount:[{ required: true, message: '请输入工号', trigger: 'change' }],
      },
      from: false, // 来自哪里，false为新建，true为更新
      treename: [],
      treeArr: [],
      idArr: [],
      id: '',
      treeSelect: [],
      ishaveBatchNumber:false,
      ishaveInsuranceSalesman:false,
      ishaveSalesmanIdentityCard:false
    }
  },
   components: {
    ztreeSelect,
  },
  created() {
    this.inquireChange();
    this.id = this.$route.params.id
    console.log('------------')
    console.log(111111)
    this.getCompanies()
    this.treeDate()
    console.log(this.id)
    if (this.id != '0') {
      this.getInfo()
      this.from = true
      console.log("bianji")
    } else {
      this.linkage()
      this.linkage2()
    }

    this.getTree()


  },
  watch: {

  },
  methods: {
    go_backs() {
      this.$router.go(-1);
    },
    // 公司
    getCompanies() {
      console.log(22222)
      let that = this
      let params = {}
      this.post(params, 'services/app/common/GetGroupInsurances').then(rs => {
        console.log(rs)
        if (rs.success) {
          that.companies = rs.result.items
        }
      })
    },
    //树
    treeDate(){
        let params={
          "queryType": 0
        }
        this.post(params,'services/app/common/GetCurrentOrganizationUnitsByType').then(rs=>{
            console.log(rs)
            if(rs.success){
              let arr = [];
              arr.push(rs.result);
              this.treedata = arr;
            }
        })
    },
    // 级联
    handleItemChange(val) {
      console.warn('级联' + val);
      const that = this;
      // console.warn(val.length);
      if (val.length == 1) {
        this.getCities(val);
      } else if (val.length == 2) {
        this.getAreas(val);
      }
    },
    // treearray(data) {
    //   // console.log(data)
    //   var treeArr = [];
    //   var treeNames = [];
    //   data.map(function(item) {
    //     if (item.isCheck) {
    //       treeArr.push(item.id)
    //       treeNames.push(item.fullName)
    //     }
    //     if (item.organizationUnits) { //遍历2级
    //       item.organizationUnits.map(function(elem) {
    //         if (elem.isCheck) {
    //           treeArr.push(elem.id)
    //           treeNames.push(elem.fullName)
    //         }
    //         if (elem.organizationUnits) { //遍历3级
    //           elem.organizationUnits.map(function(obj) {
    //             if (obj.isCheck) {
    //               treeArr.push(obj.id)
    //               treeNames.push(obj.fullName)
    //             }

    //             if (obj.organizationUnits !== null && obj.organizationUnits) { //遍历4级
    //               obj.organizationUnits.map(function(last) {
    //                 if (last.isCheck) {
    //                   treeArr.push(last.id)
    //                   treeNames.push(last.fullName)
    //                 }
    //                 //遍历3级
    //               })
    //             }
    //           })
    //         }
    //       })
    //     }
    //   })
    //   return { treeArr, treeNames };
    // },
    // 详细
    getInfo() {
      const that = this
      const params = {
        id: this.id
      }
      this.post(params, 'services/app/staff/GetStaffDetail').then(rs => {
        if (rs.success) {
        	console.log("shujusssss-----------------------------")
          console.log(rs)
          that.from = true
          that.toSystems(rs.result.staff.insuranceId)
          
          this.formLabel = rs.result.staff;
          console.log(rs.result.organizationUnitIds)
          if (rs.result.organizationUnitIds) {
            // that.formLabel.tree= rs.result.organizationUnitIds;
           // that.formLabel.tree= rs.result.organizationUnitIds;
            this.$set(that.formLabel,'tree',rs.result.organizationUnitIds)

          }

          if (rs.result.staff.regionIds) {
            let regionIds = rs.result.staff.regionIds;
            console.log("shuzushuju")
            console.log(regionIds)
            this.idArr[0] = regionIds.provinceId
            this.idArr[1] = regionIds.cityId
            this.idArr[2] = regionIds.areaId
            console.log("获取数据-------------")
            this.linkage()
            this.value1 = regionIds.provinceId;
            this.linkage2(regionIds.provinceId)
            this.formLabel.value2 = regionIds.cityId;
            this.linkage3(regionIds.cityId)
            console.log("vue2复制")
            this.value3 = regionIds.areaId
          }
        }
      })
    },
    // 树
    getTree() {
      const params = []
      this.post(params, 'services/app/common/GetOrganizationUnits').then(rs => {
        if (rs.success) {
          this.organizationUnitTree = rs.result
        }
      })
    },
    // 验证
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.save()

        } else {
          console.log('error submit')
          return false
        }
      })
    },
    // 重置
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.$router.push({
        name: 'staff'
      })
    },
    // 树值
    // getCheckedNodes() {
    //   // console.log(this.$refs.tree.getCheckedNodes())
    //   this.orgs = this.$refs.tree.getCheckedNodes()
    //   this.treename = [];
    // },
    backs() {
      console.log("back")
      this.openTree = false
      //this.formLabel.orgs=this.treeSelect
      this.$refs.tree.setCheckedKeys(this.treeSelect);
    },
    // getCheckedKeys() {
    //   if (this.value3 !== '' && this.value3 !== null) {
    //     this.formLabel.regionId = this.value3
    //   }
    //   this.openTree = false
    //   this.getCheckedNodes()
    //   let half = this.$refs.tree.getHalfCheckedKeys();
    //   let check = this.$refs.tree.getCheckedKeys();
    //   check = check.concat(half)
    //   this.treeSelect = check
    //   if (this.$refs.tree.getCheckedKeys().length == 0) {
    //     this.formLabel.orgs = [];
    //   } else {
    //     this.formLabel.orgs = this.treeSelect
    //   }

    // },
    linkage() {
      //  this.value2=''
      let params = {};
      this.post(params, 'services/app/common/GetRegionsContainsPlateCode').then(rs => {
        this.aoptions = rs.result.items;
        console.log("数据复制  省数据")
        console.log(this.aoptions)
      })
    },
    linkage2(val) {
      this.formLabel.value2 = ""
      this.value3 = ""
      this.formLabel.regionId = val
      let params = {
        id: this.value1,
      }
      this.post(params, 'services/app/common/GetRegionsContainsPlateCode').then(rs => {
        this.boptions = rs.result.items;
        console.log("数据复制  城市数据")
        console.log(this.boptions)

        for (var i = 0; i < this.boptions.length; i++) {
          if (this.boptions[i].plateCode) {
            this.boptions[i].conentname = this.boptions[i].value + '(' + this.boptions[i].plateCode + ')'
          } else {
            this.boptions[i].conentname = this.boptions[i].value
          }
        }

      })
    },
    linkage3(val) {
      console.log("qushuju------------------------")
      console.log(val)
      //val=val.key?val.key:val
      //this.value3=""
      this.formLabel.regionId = val
      console.log(val)
      if (this.id != "0") {

      } else {
        if (val.plateCode) {
          this.formLabel.value2 = val.value + '(' + val.plateCode + ')'
        } else {
          this.formLabel.value2 = val.value
        }

      }

      val = val.key ? val.key : val
      let params = {
        id: val
      }
      this.post(params, 'services/app/common/GetRegionsContainsPlateCode').then(rs => {
        this.coptions = rs.result.items;
      })
    },
    linkage4(val) {
      console.log(val)
      this.formLabel.regionId = val
    },
    inquireChange() {
      let params = {};
      this.post(params, 'services/app/common/GetRegionsContainsPlateCode').then(rs => {
        this.inquires = rs.result.items;
        console.log("数据复制  省数据")
        console.log(this.aoptions)
      })
    },
    inquireChange2(val) {
    this.formLabel.searthArea=val
      console.log(11111111);
      this.formLabel.inquire2 = ""
      this.inquire3 = ""
      let params = {
        id: this.inquire1,
      }
      this.post(params, 'services/app/common/GetRegionsContainsPlateCode').then(rs => {
        this.inquires2 = rs.result.items;
        console.log("数据复制  城市数据")
        console.log(this.boptions)

        for (var i = 0; i < this.inquires2.length; i++) {
          if (this.inquires2[i].plateCode) {
            this.inquires2[i].conentname = this.inquires2[i].value + '(' + this.inquires2[i].plateCode + ')'
          } else {
            this.inquires2[i].conentname = this.inquires2[i].value
          }
        }

      })
    },
    inquireChange3(val) {
        this.formLabel.searthArea=val
      let params = {
        id: val
      }
      this.post(params, 'services/app/common/GetRegionsContainsPlateCode').then(rs => {
        this.inquires3 = rs.result.items;
        console.log("数据复制  区数据")
        console.log(this.coptions)
      })
    },
    inquireChange4(val) {
        this.formLabel.searthArea=val
    },
    //业务系统
    toSystem(val) {
      console.log(val)
      if (val == '6273544b-c74e-44be-a044-228e1c1affb9') { //永安id
          this.organization = true;
        } else {
          this.organization = false;
        }
      if(val == '0775545a-13a5-4093-91c4-946f2e538acb'){  //太平
        this.ishaveBatchNumber = true;
      }else{
        this.ishaveBatchNumber = false;
      }
      if(val == 'bc8a88e6-df72-46f4-a88c-688bf7a1888b'){  //泰山
        this.ishaveInsuranceSalesman = true;
        this.ishaveSalesmanIdentityCard = true;
      }else{
        this.ishaveInsuranceSalesman = false;
        this.ishaveSalesmanIdentityCard = false;
      }
      if(val=="7da11e03-7c03-4eb4-b5a6-d1d5b7cb5a6e" || val=="f8b540fb-4aa0-438e-954b-5f2d5eb6f66a"){
      	this.subaccount=true
      }else{
      	this.subaccount=false
      	
      }
      let params = {
        insuranceId: val
      }
      this.post(params, 'services/app/common/GetInsuranceSystems').then(rs => {
        console.log(rs.result.items)
        if (rs.result.items.length == 1) {
         // this.formLabel.insuranceSystemId = rs.result.items[0].id
            Vue.set(this.formLabel,"insuranceSystemId",rs.result.items[0].id)
          this.types = rs.result.items
        } else {
        	
          //this.formLabel.insuranceSystemId = '';
         
          this.types = rs.result.items
          Vue.set(this.formLabel,"insuranceSystemId","")
        };
        
      })
    },
		toSystems(val) {
      console.log(val)
      if (val == '6273544b-c74e-44be-a044-228e1c1affb9') { //永安id
          this.organization = true;
        } else {
          this.organization = false;
        }
      if(val == '0775545a-13a5-4093-91c4-946f2e538acb'){  //太平
        this.ishaveBatchNumber = true;
      }else{
        this.ishaveBatchNumber = false;
      }
      if(val == 'bc8a88e6-df72-46f4-a88c-688bf7a1888b'){  //泰山
        this.ishaveInsuranceSalesman = true;
        this.ishaveSalesmanIdentityCard = true;
      }else{
        this.ishaveInsuranceSalesman = false;
        this.ishaveSalesmanIdentityCard = false;
      }
      if(val=="7da11e03-7c03-4eb4-b5a6-d1d5b7cb5a6e" || val=="f8b540fb-4aa0-438e-954b-5f2d5eb6f66a"){
      	this.subaccount=true
      }else{
      	this.subaccount=false
      	
      }
      let params = {
        insuranceId: val
      }
      this.post(params, 'services/app/common/GetInsuranceSystems').then(rs => {
        console.log(rs.result.items)
        if (rs.result.items.length == 1) {
         
          this.types = rs.result.items
        } else {
        	
         
          this.types = rs.result.items
        };
        
      })
    },

    // 保存
    save() {
      const that = this
      if (!this.from) {
        console.log('走创建')
        // 创建接口的参数

        const staffadd = Object.assign({}, this.formLabel);
        if (typeof staffadd.regionId == 'object') {
          staffadd.regionId = staffadd.regionId.key;
        }
        const paramsadd = {
          organizationUnitIds: this.formLabel.tree, // 组织树
          staff: staffadd
        }
        console.warn(paramsadd)
        // 判断走创建是不是选了组织权限
        that.post(paramsadd, 'services/app/staff/CreateStaff').then(rs => {
          console.log(rs)
          if (rs.success) {
            this.loading = false;
            this.successNot();
            console.log('成功-----------')
            // this.$router.push({
            //   name: "staff"
            // })
            this.$router.go(-1);


          } else {
            this.loading = false;
            this.failNot(rs.error.message)
          }
        })
      } else {
        console.log('走编辑')
        // 编辑接口的参数
        if(this.formLabel.insuranceId == '0775545a-13a5-4093-91c4-946f2e538acb'){
          this.formLabel.insuranceSalesman = '';
          this.formLabel.salesmanIdentityCard = '';
        }
        if(this.formLabel.insuranceId == 'bc8a88e6-df72-46f4-a88c-688bf7a1888b'){
          this.formLabel.batchNumber = '';
        }
        const staffd = Object.assign({}, this.formLabel);
        const params = {
          organizationUnitIds: this.formLabel.tree, // 组织树
          staff: staffd
        }
        that.post(params, 'services/app/staff/UpdateStaff').then(rs => {
          console.log(rs)
          if (rs.success) {
            this.loading = false;
            console.log('成功------------')
            this.successNot();
            // this.$router.push({
            //   name: 'staff'
            // })
             this.$router.go(-1);

          } else {
            this.loading = false;
            this.failNot(rs.error.message)
          }
        })
      }
    },
    //保存成功提示
    successNot() {
      var txt = '';
      if (this.id == '0') {
        txt = '工号新建成功'
      } else {
        txt = '工号保存成功'
      }
      const h = this.$createElement;
      this.$notify({
        title: '成功',
        message: txt,
        type: 'success',
        customClass: "el-notification-success"
      });
    },
    //保存失败提示
    failNot(message) {
      const h = this.$createElement;
      this.$notify.error({
        title: '失败',
        message: message,
        duration: 0,
        customClass: "el-notification-error"
      });
    }

  }
}

</script>
<style lang='scss' scoped>
.info_box_top {
  width: 100%;
  height: 60px;
  text-align: center;
  font-size: 18px;
  color: #333333;
  line-height: 60px;
  border-bottom: 1px solid #ff7819;
  position: relative;
  .backgo {
    position: absolute;
    height: 60px;
    width: 60px;
    line-height: 60px;
    font-size: 16px;
    color: #ff7819;
    top: 0;
    left: 23px;
    padding: 0;
    margin: 0;
    cursor: pointer;
  }
  i {
    margin-right: 10px;
    color: #ee6000;
  }
}
.firstM {
  margin-bottom: 30px;
}
.toCenter {
  text-align: center;
  margin-top: 50px;
}





.form-staff {
  // margin: 15px 100px 0 120px;
  .form-tab {
      width: calc(100% - 140px);
      float: right;
      background: #f9f9f9;
      padding-top: 22px;
      padding-left: 20px;
  }
}

.staff {
  background-color: #fff;
  padding: 30px 25px;
}

.form-top1 {
  width: 140px;
    float: left;
    font-size: 18px;
    color: #333333;
    letter-spacing: 2px;
    text-align: center;
  .form-title {
    font-size: 16px;
    color: #555;
  }
}

</style>
